package com.gxuwz.zlc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gxuwz.zlc.entity.User;
import com.gxuwz.zlc.mapper.UserMapper;
import com.gxuwz.zlc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    @Override
    public User queryUserByName(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public void addUser(User user) {
        userMapper.insert(user);
    }

    @Override
    public void updateUser(User user) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("username",user.getUsername());
        userMapper.update(user,wrapper);
    }
}
